#include "VertexBufferLayout.hpp"
#include<renderpch.hpp>
#include<VertexArray.hpp>


VertexArray::VertexArray()
{
   glGenVertexArrays(1, &myRendererID);
   

}


VertexArray::~VertexArray()
{
    glDeleteVertexArrays(1,&myRendererID);
}

   

void VertexArray::AddBuffer(VertexBuffer& vb,VertexBufferLayout layout)
{
    glBindVertexArray(myRendererID);
    vb.Bind();
    const auto& elements=layout.GetElements();
    unsigned int offset=0;
    for(unsigned int i=0;i<elements.size();i++)
    {
    const auto& element=elements[i];
    glEnableVertexAttribArray(i);
    glVertexAttribPointer(i, element.count, element.type,element.normalized, layout.GetStride(), (void*)offset);
    offset+=element.count*VertexBufferElement::GetSizeOfType(element.type);
    }

}

void VertexArray::Bind()
{
   glBindVertexArray(myRendererID);
}


void VertexArray::UnBind()
{
   glBindVertexArray(0);
}
